package vista;
import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import bean.JTextFieldValidator;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaCategoria extends javax.swing.JFrame implements modelo.abstractfactory.AbstractFactoryVentana {
	
	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel panCategoria;
	private JButton btnCancelar;
	private JButton btnModificar;
	private JButton btnDeshacer;
	private JButton btnSalir;
	private JButton btnGuardar;
	private JTextFieldValidator txtDescripcion;
	private JTextFieldValidator txtNombreCategoria;
	private JTextFieldValidator txtCodigoCategoria;
	private JLabel lblDescripcion;
	private JLabel lblNombre;
	private JLabel lblCodigo;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	private static VentanaCategoria instancia;

	public final static synchronized VentanaCategoria getInstancia() {
		if (instancia == null)
			instancia = new VentanaCategoria();
		return instancia;
	}
		
	public VentanaCategoria() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setTitle("Registrar Categoria");
			{
				panCategoria = new JPanel();
				getContentPane().add(panCategoria, BorderLayout.CENTER);
				panCategoria.setLayout(null);
				panCategoria.setBackground(new java.awt.Color(255,255,255));
				{
					lblCodigo = new JLabel();
					panCategoria.add(lblCodigo);
					lblCodigo.setText("Codigo");
					lblCodigo.setBounds(42, 49, 72, 21);
					lblCodigo.setForeground(new java.awt.Color(18,6,249));
					lblCodigo.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					lblNombre = new JLabel();
					panCategoria.add(lblNombre);
					lblNombre.setText("Nombre");
					lblNombre.setBounds(42, 87, 72, 21);
					lblNombre.setFont(new java.awt.Font("Comic Sans MS",1,12));
					lblNombre.setForeground(new java.awt.Color(18,6,249));
				}
				{
					lblDescripcion = new JLabel();
					panCategoria.add(lblDescripcion);
					lblDescripcion.setText("Descripcion");
					lblDescripcion.setBounds(42, 126, 72, 21);
					lblDescripcion.setForeground(new java.awt.Color(19,6,249));
					lblDescripcion.setFont(new java.awt.Font("Comic Sans MS",1,12));
				}
				{
					txtCodigoCategoria = new JTextFieldValidator(2,JTextFieldValidator.SOLO_NUMEROS);
					panCategoria.add(txtCodigoCategoria);
					txtCodigoCategoria.setBounds(126, 46, 133, 26);
					txtCodigoCategoria.setEditable(false);
				}
				{
					txtNombreCategoria = new JTextFieldValidator(JTextFieldValidator.LETRAS_Y_ESPACIOS);
					panCategoria.add(txtNombreCategoria);
					txtNombreCategoria.setMaximaLongitud(50);
					txtNombreCategoria.setBounds(126, 84, 133, 27);
				}
				{
					txtDescripcion = new JTextFieldValidator(JTextFieldValidator.LETRAS_Y_ESPACIOS);
					panCategoria.add(txtDescripcion);
					txtDescripcion.setMaximaLongitud(50);
					txtDescripcion.setBounds(126, 123, 133, 27);
				}
				{
					btnGuardar = new JButton();
					panCategoria.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(42, 170, 106, 40);
					btnGuardar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnGuardar.setForeground(new java.awt.Color(252,221,3));
					btnGuardar.setBackground(new java.awt.Color(18,6,249));
					btnGuardar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/disk.gif")));
				}
				{
					btnCancelar = new JButton();
					panCategoria.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(167, 170, 106, 40);
					btnCancelar.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnCancelar.setForeground(new java.awt.Color(252,221,3));
					btnCancelar.setBackground(new java.awt.Color(18,6,249));
					btnCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/cancelar.gif")));
				}
				{
					btnSalir = new JButton();
					panCategoria.add(btnSalir);
					panCategoria.add(getBtnDeshacer());
					panCategoria.add(getBtnModificar());
					btnSalir.setText("Salir");
					btnSalir.setBounds(294, 170, 106, 40);
					btnSalir.setFont(new java.awt.Font("Comic Sans MS",1,12));
					btnSalir.setForeground(new java.awt.Color(252,221,3));
					btnSalir.setBackground(new java.awt.Color(18,6,249));
					btnSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/cross.gif")));
				}
			}
			pack();
			this.setSize(448, 270);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void addListener(ActionListener actionlistener){
		this.btnGuardar.addActionListener(actionlistener);
		this.btnCancelar.addActionListener(actionlistener);
		this.btnSalir.addActionListener(actionlistener);
		this.btnDeshacer.addActionListener(actionlistener);
		this.btnModificar.addActionListener(actionlistener);
	}
	
	public void setCodigoCategoria(String codigo){
		this.txtCodigoCategoria.setText(codigo);
	}
	
	public String getCodigoCategoria(){
		return this.txtCodigoCategoria.getText();
	}
	
	public String getNombreCategoria(){
		return txtNombreCategoria.getText();
	}
	
	public String getDescripcion(){
		return txtDescripcion.getText();
	}
	
	public void borrarDatos(){
		txtNombreCategoria.setText("");
		txtDescripcion.setText("");
	}
	
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public void setDescripcion(String descripcion) {
		// TODO Auto-generated method stub
		txtDescripcion.setText(descripcion);
	}

	public void setNombre(String nombre) {
		// TODO Auto-generated method stub
		txtNombreCategoria.setText(nombre);
	}
	
	private JButton getBtnDeshacer() {
		if(btnDeshacer == null) {
			btnDeshacer = new JButton();
			btnDeshacer.setText("Deshacer");
			btnDeshacer.setBounds(277, 37, 123, 43);
			btnDeshacer.setBackground(new java.awt.Color(18,6,249));
			btnDeshacer.setForeground(new java.awt.Color(252,221,3));
			btnDeshacer.setFont(new java.awt.Font("Comic Sans MS",1,12));
			btnDeshacer.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/deshacer2.gif")));
		}
		return btnDeshacer;
	}
	
	private JButton getBtnModificar() {
		if(btnModificar == null) {
			btnModificar = new JButton();
			btnModificar.setText("Modificar");
			btnModificar.setBounds(277, 92, 123, 38);
			btnModificar.setBackground(new java.awt.Color(18,6,249));
			btnModificar.setFont(new java.awt.Font("Comic Sans MS",1,12));
			btnModificar.setForeground(new java.awt.Color(252,221,3));
			btnModificar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/modificar.gif")));
			btnModificar.setEnabled(false);
		}
		return btnModificar;
	}
	
	public void habilitarModificar(){
		btnModificar.setEnabled(true);
	}
	
	public void deshabilitarGuardar(){
		btnGuardar.setEnabled(false);
	}
	
	public void habilitarGuardar(){
		btnGuardar.setEnabled(true);
	}
	
	public void deshabilitarModificar(){
		btnModificar.setEnabled(false);
	}

}
